package com.misweb.ibase;

import com.misweb.ibase.tool.DateUtil;

import java.util.List;

/**
 * Created by shicheng on 2015/4/9.
 */
public class Cookies {


    public Cookies(String id,String ccs ,String net,String laowugongren){
        this.Cookie_SessionId=id;
        this.Cookie_CCS=ccs;
        this.Cookie_DotNet=net;
        this.Cookie_Laowugongren=laowugongren;
        this.SetCookiesTime=DateUtil.getDate();
    }
    public  Cookies(){

    }

    //通过   List<String> allCookies 获取cookies
     public Cookies( List<String> allCookies){

         if (allCookies!= null) {
             for (String rawCookie: allCookies) {
                 if (rawCookie.startsWith(GlobalData.Cookie_SessionId)) {
                     int valueEnd = rawCookie.indexOf(';');
                     if (valueEnd == -1) {
                         valueEnd = rawCookie.length();
                     }
                     this.Cookie_SessionId=rawCookie.substring((rawCookie.indexOf("=")+ 1), valueEnd);
                 }
                 if (rawCookie.startsWith(GlobalData.Cookie_CCS)) {
                     int valueEnd = rawCookie.indexOf(';');
                     if (valueEnd == -1) {
                         valueEnd = rawCookie.length();
                     }
                     this.Cookie_CCS=rawCookie.substring((rawCookie.indexOf("=")+ 1), valueEnd);
                 }
                 if (rawCookie.startsWith(GlobalData.Cookie_DotNet)) {
                     int valueEnd = rawCookie.indexOf(';');
                     if (valueEnd == -1) {
                         valueEnd = rawCookie.length();
                     }
                     this.Cookie_DotNet=rawCookie.substring((rawCookie.indexOf("=")+ 1), valueEnd);
                 }

             }
             this.SetCookiesTime=DateUtil.getDate();
         }
    }
    public   String Cookie_SessionId;
    public   String Cookie_CCS;
    public   String Cookie_DotNet;
    public   String Cookie_Laowugongren;

    public String  SetCookiesTime;

    public boolean IsCookieComplete(){
        try {
            if (this.Cookie_SessionId.isEmpty() || Cookie_CCS.isEmpty() || Cookie_DotNet.isEmpty()) {
                return false;
            }
        }catch(Exception e){
            return  false;
        }
        return  true;
    }
}
